import { ComponentWithComputed } from 'miniprogram-computed';
// @ts-ignore
import { getBindWechatQrCode } from '@/api/user';

ComponentWithComputed({
  data: {
    /** 是否显示弹窗 */
    isShow: false,
    /** 二维码地址 */
    qrCode: '',
  },
  pageLifetimes: {
    hide() {
      this.setData({
        isShow: false,
      });
    },
  },
  methods: {
    /** 获取并修改二维码地址 */
    async getQrCode() {
      const res = await getBindWechatQrCode();
      this.setData({
        qrCode: res,
      });
    },
    /** 显示弹窗 */
    open() {
      this.getQrCode();
      this.setData({
        isShow: true,
      });
    },
    /** 关闭弹窗 */
    close() {
      this.setData({
        isShow: false,
      });
    },
    onClose() {
      this.setData({
        isShow: false,
      });
    },
  },
});
